/*
 *  Charge.cpp
 *  :
 *
 *  Created by Tim Uusitalo on 4/3/11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#include "Charge.h"

#include "StdInclude.cpp"
#include <cmath>
#include "MathUtility.h"

using namespace MathUtility;

const float Charge::MAX_LENGTH = 1/200.0f;

Charge::Charge()
: charge(0.0f), angle(0.0f), potential(-1.0f)
{
}

/**
 * Constructor
 * @param c - the charge
 * @param a - the angle for the current charge
 */
Charge::Charge(const float c, const float a)
: charge(c), angle(a), potential(-1.0f)
{
}

Charge::~Charge()
{
}

/**
 * Updates the current potential
 */
void Charge::update()
{
//potential = charge / (pow((1-(length*MAX_LENGTH)), 2));

	position = calculatePosition((angle), length);
}

/**
 * Sets charge
 * @param c - incoming charge
 */
void Charge::setCharge(const float c)
{
	charge = c;
}

/**
 * Sets the angle for the current charge
 * @param a - incoming angle
 */
void Charge::setAngle(const float a)
{
	angle = a;
}

/**
 * Sets length
 * @param length - incoming length
 */
void Charge::setLength(const float length)
{
	this->length = length;
}

/**
 * Sets position of the angle
 * @param pos - incoming position
 */
void Charge::setPos(const int pos)
{
	this->pos = pos;
}

/**
 * Returns the charge
 */
const float Charge::getCharge() const
{
	return charge;
}

/**
 * Returns the angle
 */
const float Charge::getAngle() const
{
	return angle;
}

/**
 * @returns the length
 */
const float Charge::getLength() const
{
	return length;
}

/**
 *
 * @returns the position
 */
const int Charge::getPos() const
{
	return pos;
}
/**
 * @return - current potential
 */
const float Charge::getPotential() const
{
	return potential;
}

const Vector2 Charge::getPosition() const
{
	return position;
}

/**
 * Calculate a potential between two different charges according to
 * coulomb's law
 * @param c1 - the first charge
 * @param c2 - second charge
 * @return - Potential between the charges
 */

const float Charge::getPotentialFromCharges(const Charge& c1, const Charge& c2, const float distance)
{
	float potential = c1.getCharge() * c2.getCharge();


	potential /= (pow(((1-(distance*MAX_LENGTH))), 2));

	return potential;

}

const float Charge::getPotentialFromChargesDistanceNonSquared(const Charge& c1, const Charge& c2, const float distance)
{
	float potential = c1.getCharge() * c2.getCharge();


	potential /= (distance*MAX_LENGTH);

	return potential;
}
